<?php
class user extends common{

	private $user='user';											//会员表
	private $user_educate_experience='user_educate_experience';		//会员教育经历
	private $user_oversea_experience='user_oversea_experience';		//会员海外经历
	private $user_work_experience='user_work_experience';		//会员海外经历
	private $country='country';										//国家表

	private $message='user_message';								//消息表
	private $message_list='user_message_list';						//消息用户表
	
	function __construct(){	
		$pagec = new page($_GET['page']);
		parent::__construct($pagec);
	}	

	/**
	 * 会员列表
	 * @param  string  $where 
	 * @param  string  $key   
	 * @param  integer $page  
	 * @return array
	 * @author wxy         
	 */
	function userList($where='',$key='u.*',$page=0){
		$sql=$this->user.' u where 1=1 '.$where;
		$sqlnum=$page==0?'':$sql;
		$list=$this->getList($sql,$sqlnum,$key);
		return $list;	
	}
 
	/**
	 * 会员基本信息
	 * @param  [type] $user_id 
	 * @param  string $key     
	 * @return array          
	 */
	function userInfo($user_id,$key='*'){
		$info=$this->getInfo($this->user,$user_id,$key);
		return $info;
	}

	/**
	 * 会员教育经历
	 * @param  string  $where 
	 * @param  string  $key   
	 * @param  integer $page  
	 * @return array  
	 * @author wxy       
	 */
	function educateList($where='',$key='*',$page=0){
		$sql=$this->user_educate_experience.' ue where 1=1 '.$where;
		$sqlnum=$page==0?'':$sql;
		$list=$this->getList($sql,$sqlnum,$key);
		return $list;
	}


	/**
	 * 会员工作经历
	 * @author JSY
	 * @param  string  $where 
	 * @param  string  $key   
	 * @param  integer $page  
	 * @return array  
	 * @author wxy       
	 */
	function workList($where='',$key='*',$page=0){
		$sql=$this->user_work_experience.' ue where 1=1 '.$where;
		$sqlnum=$page==0?'':$sql;
		$list=$this->getList($sql,$sqlnum,$key);
		return $list;
	}

	/**
	 * 会员海外经历列表
	 * @param  string  $where 
	 * @param  string  $key   
	 * @param  integer $page  
	 * @return array        
	 */
	function overseaList($where='',$key='*',$page=0){
		$sql=$this->user_oversea_experience.' us left join '.$this->country.' c 
			 on us.country_id=c.id where 1=1 '.$where;
		$sqlnum=$page==0?'':$sql;
		$list=$this->getList($sql,$sqlnum,$key);
		return $list;
	}

	/**
	 * 会员删除
	 * @param  string $user_ids 
	 * @return bool           
	 */
	function delUser($user_ids){
		$user_ids.=',';
		$this->del($this->user_educate_experience,$user_ids,'','user_id');
		$this->del($this->user_oversea_experience,$user_ids,'','user_id');
		$res=$this->del($this->user,$user_ids);
		return $res;
	}



	/**
	 * 站内信添加
	 * @author	jsy	
	 * @param	array	$arr			单数组
	 * @param	array	$list			批量数组
	 * @return 	bool
	 */
	function message_add($arr,$list){
		if(!empty($arr) && !empty($list)){

			$res = $this->insert($this->message,$arr);	//插入活动
			$id = $this->insert_id();
			if($id > 0){
				$sql = ' INSERT INTO '.$this->message_list. '(msg_id,user_id) VALUES ';
				foreach($list as $v){
					$sql.='(';
					$sql.= $id.",".$v['to_user'];
					$sql .= '),';
				}
				$sql = substr($sql,0,-1);
				$res = $this->query($sql);
			}
		}
		return $res;
	}


	/**
	 * 站内信列表
	 * @param  string  $where 
	 * @param  string  $key   
	 * @param  integer $page  
	 * @return array        
	 */
	function message_list($where='',$key='m.*',$page=0){
		$sql=$this->message.' m  WHERE 1=1 '.$where." ORDER BY m.create_time desc";
		$sqlnum=$page==0?'':$sql;
		$list=$this->getList($sql,$sqlnum,$key);
		return $list;
	}

	/**
	 * 站内信信息
	 * @param  int    $id 
	 * @param  string $key     
	 * @return array          
	 */
	function message_info($id,$key='*'){
		$info=$this->getInfo($this->message,$id,$key);
		return $info;
	}

	

}
?>